﻿using System;
using System.Collections.Generic;
using System.Text;
using Tracy.CoreLib.Data;
using Tracy.CoreLib;

namespace Tracy.Engine
{
    /// <summary>
    /// Tracy总线，提供对各种资源的访问
    /// </summary>
    public partial class TracyBus
    {
        private static Object s_lock = new Object();

        private static TracyEngine _engine;

        public TracyEngine Engine
        {
            get { return _engine; }
        }

        public TracyBus(TracyEngine engine)
        {
            _engine = engine;
        }

        private static SettingsManager _settingsManager;
        /// <summary>
        /// 设置管理器
        /// </summary>
        public SettingsManager TracySettings
        {
            get 
            {
                if (_settingsManager == null)
                {
                    lock (s_lock)
                    {
                        if (_settingsManager == null)
                        {
                            _settingsManager = new SettingsManager();
                        }
                    }
                }
                return _settingsManager;
            }
        }

        private static PluginManager _pluginManager;
        /// <summary>
        /// 插件管理器
        /// </summary>
        public PluginManager TracyPlugins
        {
            get 
            {
                if (_pluginManager == null)
                {
                    lock (s_lock)
                    {
                        if (_pluginManager == null) _pluginManager = new PluginManager(TracySettings[Constants.CONST_SETTING_PLUGINFOLDER]);
                    }
                }
                return _pluginManager;
            }
        }

        private static DownloadDispatcher _downloadDispatcher;
        /// <summary>
        /// 下载任务分配器
        /// </summary>
        public DownloadDispatcher TracyDownloader
        {
            get 
            {
                if (_downloadDispatcher == null)
                {
                    lock (s_lock)
                    {
                        if (_downloadDispatcher == null) _downloadDispatcher = new DownloadDispatcher(this);
                    }
                } 
                return _downloadDispatcher;
            }
        }

        private static TagManager _tagManager;
        /// <summary>
        /// 标签管理器
        /// </summary>
        public TagManager TracyTagManager
        {
            get
            {
                if (_tagManager == null)
                {
                    lock (s_lock)
                    {
                        if (_tagManager == null) _tagManager = new TagManager(this);
                    }
                }
                return _tagManager;
            }
        }

        #region 配置数据
        private static RssFilterProvider _filterProvider;
        /// <summary>
        /// 过滤器
        /// </summary>
        public RssFilterProvider FilterProvider
        {
            get 
            {
                if (_filterProvider == null)
                {
                    lock(s_lock){
                        if (_filterProvider == null)_filterProvider = new RssFilterProvider();
                    }
                }
                return _filterProvider; 
            }
        }

        private static RssFeedSourceProvider _feedSourceProvider;
        /// <summary>
        /// 订阅源
        /// </summary>
        public RssFeedSourceProvider FeedSourceProvider
        {
            get 
            {
                if (_feedSourceProvider == null)
                {
                    lock(s_lock)
                    {
                        if (_feedSourceProvider == null) _feedSourceProvider = new RssFeedSourceProvider();
                    }
                } 
                return _feedSourceProvider;
            }
        }

        private static SiteSchemaProvider _schemaProvider;
        /// <summary>
        /// 站点模式
        /// </summary>
        public SiteSchemaProvider SchemaProvider
        {
            get
            {
                if (_schemaProvider == null)
                {
                    lock (s_lock)
                    {
                        if (_schemaProvider == null) _schemaProvider = new SiteSchemaProvider();
                    }
                } 
                return _schemaProvider;
            }
        }
        #endregion

        #region 用户数据
        private static ResourceProvider _resourceProvider;
        /// <summary>
        /// 资源
        /// </summary>
        public ResourceProvider ResourceProvider
        {
            get 
            { 
                if (_resourceProvider == null)
                {
                    lock(s_lock)
                    {
                        if (_resourceProvider == null) _resourceProvider = new ResourceProvider();
                    }
                } 
                return _resourceProvider;
            }
        }
        #endregion



    }
}
